#ifndef __AHCOMPUTE_UTILS_H__
#define __AHCOMPUTE_UTILS_H__

#include <cstddef>

#include <condition_variable>
#include <mutex>
#include <chrono>

namespace ah_compute
{

typedef size_t AHRet;

extern bool g_running;

struct WorkerExeCtrl
{
private:
    std::condition_variable stream_exe_cv;
    std::mutex stream_exe_mutex;

public:
    WorkerExeCtrl() {}

    inline void WaitFor(int time_ms)
    {
        using unique_lock = std::unique_lock<std::mutex>;
        unique_lock lock(stream_exe_mutex);
        stream_exe_cv.wait_for<float, std::ratio<1>>(lock,
            std::chrono::duration<float, std::ratio<1>>(time_ms / 1000.0f));
    }

    inline void Notify()
    {
        stream_exe_cv.notify_all();
    }
};

inline WorkerExeCtrl& GetWorkerExeCtrl()
{
    static WorkerExeCtrl stream_exe_ctrl;
    return stream_exe_ctrl;
}


} // namespace ah_compute

#endif // __AHCOMPUTE_UTILS_H__